package main

import (
	"accx/appFramework"
	"accx/appFramework/m_config"
	"accx/appFramework/m_router"
	"accx/appFramework/server"
	"accx/models/accx"
	"github.com/cihub/seelog"
	"os"
)

func main() {
	config := m_config.GetConfigInstance()
	str := os.Getenv("APP_CONFIG_PATH")
	AppConfigPath := m_config.AppConfigPath
	if len(str) != 0 {
		AppConfigPath = str
	}
	accxAndAllaccxData := m_config.NewAccxAndAllaccxData()
	sysconfigData := m_config.NewSysconfigData()
	sysconfigData.Init(m_config.SysconfigfilePath)
	accxAndAllaccxData.Init(sysconfigData.SERVERS.OAMIP)
	if accxAndAllaccxData.Group == "T1" {
		//TODO:T1
	}
	m_config.MyaccxInit()
	// Load the m_config from the file
	config.LoadConfig(AppConfigPath)
	app := appFramework.NewApp(config)
	//new Http server
	h1Server := server.NewHttp2Server()
	h2cServer := server.NewHttp2Server()
	h1Server.RegisterHandler(m_router.NewRouter(m_router.NewAccxRoutes()))
	h2cServer.RegisterHandler(m_router.NewRouter(m_router.NewSyncRoutes()))

	app.AddServer(h1Server)
	app.AddServer(h2cServer)
	err := app.Initialize()
	if err != nil {
		seelog.Error("failed to initialize, error: ", err.Error())
	}
	app.Start()
	var smfregist accx.SmfRegistInfo
	smfregist.LocalSmfRegist()
	var hand accx.HandShake
	go hand.GoHandShake()
	go accx.Goheart()
	defer app.Cleanup()
}
